package com.kmu.lwl.controller;

import com.kmu.lwl.entiy.Login;
import com.kmu.lwl.entiy.Student;
import com.kmu.lwl.imp.AlterDao;
import com.kmu.lwl.imp.SelectDao;
import com.kmu.lwl.imp.impl.AlterDaoimpl;
import com.kmu.lwl.imp.impl.SelectDaoimpl;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import java.util.List;
import java.util.Map;

public class AlterController extends ActionSupport {
   private Student student;

    public Student getStudent() {
        return student;
    }

    public void setStudent(Student student) {
        this.student = student;
    }

    public String studentInfo() throws Exception {
        Map session = (Map) ActionContext.getContext().getSession();
        Login user = (Login) session.get("user");
        SelectDao selectDao = new SelectDaoimpl();
        Student stu = selectDao.selectMessage(user.getLoginName());
        List allMajor = selectDao.getAllMajor();
        Map request = (Map) ActionContext.getContext().getSession();
        request.put("updateStudent",stu);
        Map request1 = (Map) ActionContext.getContext().get("request");
        request1.put("allMajor",allMajor);
        return SUCCESS;
    }

    public String studentUpdate() throws Exception{
        AlterDao alterDao = new AlterDaoimpl();

        Student stu = new Student();
        stu.setId(student.getId());
        stu.setName(student.getName());
        stu.setBirth(student.getBirth());
        stu.setGender(student.getGender());
        stu.setMajorId(student.getMajorId());
        stu.setTotalCredit(student.getTotalCredit());
        stu.setNote(student.getNote());
        alterDao.update(stu);
        return SUCCESS;
    }
}
